package com.net.udp
{
	import flash.events.NetStatusEvent;
	import flash.net.NetConnection;
	import flash.net.NetGroup;
	
	public class DynamicNetGroup extends NetGroup
	{
		public var name:String;
		public var callback:Function;
		public function DynamicNetGroup(connection:NetConnection, groupspec:String)
		{
			super(connection, groupspec);
		}
		
		/**
		 * 模拟广播给组内所有客户端，包括自己
		 * 
		 */
		public function broadcast(func:String, ...args):void{
			var msg:Array = new Array;
			msg = msg.concat(func, args);
			sendToAllNeighbors(msg);
			var event:NetStatusEvent = new NetStatusEvent(NetStatusEvent.NET_STATUS);
			event.info = {};
			event.info.code = "NetGroup.SendTo.Notify";
			event.info.message = msg;
			dispatchEvent(event);
		}
		
		/**
		 * 向所有邻居广播，不包括自己
		 */
		public function broadcastAllNeighbors(func:String, ...args):void{
			var msg:Array = new Array;
			msg = msg.concat(func, args);
			sendToAllNeighbors(msg);
		}
	}
}